home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CICA 1993 April
/
CICA MS Windows - April 1993.iso
/
unzipped
/
programr
/
vbasic
/
cmdlg2
/
dialog.txt
< prev
next >
Wrap
Text File
|
1992-08-10
|
3KB
|
79 lines
It has proved difficult to retrieve the printer Driver, DeviceName and Port
combination selected using the MhPrintDlg%() function (without using the 'Def'
version to change the default printer and using GetProgileStringto load the Windows,Device line)
However, with the help of the DIALOG.ZIP file uploaded by
Costas Kitsos (73667,1755) we have derived the following:
The DevNames data Structure contains the following items:
wDriverOffset : Offset to start of DriverName e.g. 'Canon LPB-8 III'
wDeviceOffset : Offset to start of DeviceName e.g. 'LBPIII'
wOutputOffset : Offset to start of PortName e.g. 'LPT1'
wDefault : 1 if default printer choosen, 0 otherwise.
All offsets are relative to the base of the DevNames structure.
Maximum Sizes:
32 for device + nul
8 for driver + nul
4 for port + nul
Total = 47 extra bytes
Type DevNames
wDriverOffset As Integer
wDeviceOffset As Integer
wOutputOffset As Integer
wDefault As Integer
cNames As String * 47
End Type
Dim N As DevNames
Dim P As MhPrintDlog
If P.hDevNames <> 0 Then
Address = GlobalLock(P.hDevNames) ' Lock handle and obtain address
Call hmemcpy(N, ByVal Address, Len(N)) ' Copy to VB variable.
Ok = GlobalUnlock(P.hDevNames) ' Unlock handle.
' The Memory used by the Devnames structure may be freed with
'
' Ok = GlobalFree(P.hDevNames)
'
' but if you call the the printer dialog again you need it
' to keep the settings currently in use
' Correct the offsets to to the base of the cNames string
N.wDeviceOffset = N.wDeviceOffset - 7
N.wDriverOffset = N.wDriverOffset - 7
N.wOutputOffset = N.wOutputOffset - 7
lenDevice = N.wDriverOffset - N.wDeviceOffset - 1
lenDriver = N.wOutputOffset - N.wDriverOffset - 1
' and retrieve the strings
PrnDevice$ = Mid$(N.cNames, N.wDeviceOffset, lenDevice)
PrnDriver$ = Mid$(N.cNames, N.wDriverOffset, lenDriver)
PrnPort$ = Mid$(N.cNames, N.wOutputOffset, 4)
End If
The PrnDevice$,PrnDriver$ and PrnPort$ may then be used
with CreateDC to generate a Printer device context whenever
printing is required. (Without presenting the common dialog):
In Global module:
Declare Function CreateDC Lib "GDI" (ByVal lpDriverName As String, ByVal
lpDeviceName As String, ByVal lpOutput As String,ByVal pInitData As String) As
Integer
Declare Function DeleteDC Lib "GDI" (ByVal hDC As Integer) As Integer
Where printing required:
hDC = CreateDC(PrnDevice$, PrnDriver$, PrnPort$, hDevMode)
'
' StartDoc Escape
' For each page:
' API Printing calls...
' NewPage Escape
' EndDoc Escape
lOk = DeleteDC(hDC)